print("");

# 1.函数定义
"""
def <函数名>([参数]):
    函数体
    return 返回值
"""
def add(a, b):
    return a + b;

print(f"{add(1, 10)}")

# 2.各种函数定义
## 无参有返回值
def fun1():
    return 11;
## 有参有返回值
def fun2(a):
    return a;
## 有参无返回值
def fun2(a):
    return None;
## 无参无返回值
def fun2():
    return None;

# 3.全局变量与局部变量
num1 = 100;
num2 = 100;

def a():
    print("a() --> num1=%d" %num1);
    print("a() --> num2=%d" %num2);
def b():
    num1 = 200;
    global num2;
    num2 = 200;
    print("b() --> num1=%d" %num1);
    print("b() --> num1=%d" %num1);

a();
b();
print("global --> num1=%d" %num1);
print("global --> num2=%d" %num2);

# 4.多返回值
def multi_return():
    return 1,2;
x, y = multi_return();
print("接收到的函数返回值为: {x: %d,y: %d}" %(x, y));

# 5.传参
def show(name, age, gender = '男'):
    print(f"人员信息 --> 姓名:{name},性别:{gender},年龄:{age}");
# 5.1 正常传参
def show(name, age, gender):
    print(f"人员信息 --> 姓名:{name},性别:{gender},年龄:{age}");
show("小明", 20, "男");

# 5.2 关键字传参(key=value)
show(age = 18, gender = '女', name = '小红')

# 5.3 参数默认值
def show2(name, age, gender = '男'):
    print(f"人员信息 --> 姓名:{name},性别:{gender},年龄:{age}")
show2(age = 28, name = '小黑')

# 5.4 变长参数 -- 正常传参
def show3(*args):
    print(f"人员信息 --> 姓名:{args[0]},性别:{args[1]},年龄:{args[2]}")
show3("小灰", "男", 30)

# 5.5 变长参数 -- 关键字传参
def show3(**args):
    print(f"人员信息 --> 姓名:{args['name']},性别:{args['gender']},年龄:{args['age']}")
show3(age = 18, gender = '女', name = '小红')

